<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="../style/journal.css" type="text/css" />
<style type="text/css"><!--
.googleadsense {
	margin: 2px;
	padding: 0px;
//--></style><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-65008-1";
urchinTracker();
</script><title>joy in Perl</title>
</head>
<body>
<a href="index.html">Journal</a>(2005) | <a href="../blog/"><b>Blog</b></a>(2006) | <a href="http://www.fayland.org/cgi-bin/random_link.pl">RandomLink</a> | <a href="AboutFayland.html">WhoAmI</a> | <a href="LiveBookmark.html">LiveBookmark</a> | <a href="http://www.fayland.org/">HomePage</a>
<p><&lt;Previous: <a href="051212.html">my first paid Perl work</a>&nbsp;&nbsp;>>Next: <a href="DateTime.html">[DRAFT]如何处理 Perl 中的时间</a></p>
<h1>joy in Perl</h1>
<div class='content'>
<p>Category: <a href='Diary.html'>Diary</a> &nbsp; Keywords: <b>joy acme</b></p>有时候写 Perl 代码写得很累的时候，可以玩一下。<br />CPAN 中以 Acme 开头的模块很多都是用来 play 的。<br />一起来玩一下吧。<h4>Acme::Pony</h4>当然，你得先安装它。cpan <a href="http://search.cpan.org/perldoc?Acme::Pony">Acme::Pony</a><br />安装完毕后，写一个简单的 Perl 文件(t.pl)<br /><pre>use Acme::Pony;<br />print "Hello world";</pre>然后 perl t.pl<br />Woo, 再看看你的 t.pl, 看看它变成了什么：<br /><pre>use Acme::Pony;<br />        buf                     <br />       fYBUff                   <br />       YbuFFYbU                 <br />      ffYbUFfyBU                <br />     FfYBuffYbUF                <br />       FybuffyBu                <br />      ffYbufFybuf       fYbu    <br />  Ff  YbUffYBuffYBuFFybuFFyBU   <br /> fFYBUfFYbuffybUffYBUfFYBuFFYB  <br />uFF  ybUffYBUffyBUfFYbufFybUFf  <br />  yBu   ffYbuFFyBUFfybUfFybufFY <br />          BUFf     YbUFFYBuFfYb <br />          Uffy       BufFYBufFy <br />          buF         fybUfFYBU <br />           Ff        Yb UFFYBuF <br />           fX            XX XXX <br />         XXX            XX      <br />         XX             XX      <br /></pre>更惊奇的在后头，它可以被运行。 perl t.pl 输出了 Hello world<br />很不可思议吧。<h4>Acme::Bleach</h4>在 David Cantrell 写完 Acme::Pony 后很多人都开始搞怪。比如 Damian Conway, 他就写了 <a href="http://search.cpan.org/perldoc?Acme::Bleach">Acme::Bleach</a> , <a href="http://search.cpan.org/perldoc?Acme::DWIM">Acme::DWIM</a> 和 <a href="http://search.cpan.org/perldoc?Acme::Morse">Acme::Morse</a> <br />安装完它们后一个个试试吧。<br /><pre>use Acme::Bleach;<br />print "Hello world";</pre>perl t.pl 后，这文件变成了：<br /><pre>use Acme::Bleach;<br />  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;  &nbsp; &nbsp;     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br /> &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; <br />  &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;    &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      <br /> &nbsp; &nbsp;    &nbsp; &nbsp;    &nbsp; &nbsp;<br />      &nbsp; &nbsp;   &nbsp; &nbsp;<br />  &nbsp; &nbsp;  &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; <br />   &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;  <br />  &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;    <br />   &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp;   &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp;    &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp;<br />    &nbsp; &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; <br />  &nbsp; &nbsp;    &nbsp; &nbsp;   &nbsp; &nbsp;<br /> &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  </pre>是不是什么都看不见。其实其中都是空格，你用鼠标反白它就看见了。<br />再运行它 perl t.pl 就会输出 Hello world<br />都是空白的东西输出了 Hello world, 玩得还可以吧。<h4>Acme::Morse</h4><pre>use Acme::Morse;<br />print "S-O-S\n";</pre>Morse 的意思为“摩尔斯式电码”。所以运行它后该文件会变为：<br /><pre>use Acme::Morse;<br />.--.-..--..---.-.--..--.-..--..---.-.--.<br />....---..-..---.-..-.--..---.--...-.---.<br />.....-...-...-..--..-.-.-.--.-..----..-.<br />-.--.-..--..-.-...---.-..---.--..-...-..<br />--.---..</pre>还是一样，再运行它会输出 S-O-S<h3>Acme::EyeDrops</h3><a href="http://search.cpan.org/perldoc?Acme::EyeDrops">Acme::EyeDrops</a> 这是最最好玩的一个模块。想把 Perl 代码变为我们最爱的骆驼吗？跟我来吧：<br /><ol><br /><li>创立一个 helloworld.pl 文件。内容为：<br /><pre>print "hello world\n";</pre>当然也可以为你喜欢输出的内容。<br /><li>创立一个 t.pl 文件。内容为：<br /><pre>use Acme::EyeDrops qw(sightly);<br />print sightly( { Shape       => 'camel',<br />                 SourceFile  => 'helloworld.pl',<br />                 Regex       => 1 } );</pre><li>运行 perl t.pl >camel.pl<br />将运行的结果输入 camel.pl<br /><li>打开 camel.pl, Woo000ooo0o0oooooooo00oooooooooooooo! 骆驼：<br /><pre>                                      ''=~('('.'?'<br />           .'{'.(                   '`'|'%').("\["^<br />        '-').('`'|                '!').('`'|',').'"'<br /> .('['^'+')  .('['^              ')').('`'|')').('`'|<br />'.').('['^'/').('{'^            '[').'\\'.'"'.('`'|'('<br />).('`'|'%').('`'|',')          .('`'|',').('`'|"\/").(<br />  '{'^'[').('['^',').        ('`'|'/').('['^')').("\`"|<br />       ',').('`'|'$')      .'\\'.'\\'.('`'|'.').'\\'.'"'<br />      .';'.'"'."\}".     ')');$:='.'^'~';$~='@'|('(');$^=<br />     ')'^'[';$/='`'|   '.';$,='('^'}';$\='`'|'!';$:=(')')^<br />    '}';$~='*'|'`';   $^='+'^'_';$/='&amp;'|'@';$,='['&amp;('~');$\=<br />    ','^'|';$:='.'^  '~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,=<br />    '('^'}';$\='`'  |'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/=<br />    '&amp;'|'@';$,='['  &amp;'~';$\=','^'|';$:='.'^'~';$~='@'|"\(";$^=<br />    ')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'<br />    |'`';$^='+'^'_';$/='&amp;'|'@';$,='['&amp;'~';$\=','^'|';$:='.'^'~'<br />     ;$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:<br />     =')'^'}';$~='*'|'`';$^='+'^'_';$/='&amp;'|'@';$,='['&amp;'~';$\=','<br />      ^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}'<br />       ;$\='`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&amp;'|'@';$,<br />        ='['&amp;'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'['; $/=<br />         '`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`'  ;$^<br />          ='+'^'_';$/='&amp;'|'@';$,='['&amp;'~';$\=','^'|' ;$:='.'^  '~'<br />            ;$~='@'|'(';$^=')'^'[';$/='`'|"\.";$,=  '('^'}'   ;$\<br />             ='`'| '!';$:=')'^'}';$~='*'|"\`";$^=   '+'^'_'   ;$/<br />                   ='&amp;'|'@';$,='['&amp;'~';$\=(',')^    '|';$:=   '.'<br />                   ^'~';$~=    '@'|'(';$^ ="\)"^     '[';$/   =(<br />                   ('`'))|     "\.";$,=   ('(')^     '}';$\  =(<br />                   ('`'))|     "\!";$:=   "\)"^       "\}";  (<br />                   ($~))=      '*'|'`';   ($^)         ='+'<br />                   ^"\_";     $/=('&amp;')|   '@';         ($,)<br />                    ='['&amp;     "\~";$\=    ','^         '|';<br />                    ($:)=     '.'^'~'     ;$~=         '@'|<br />                    '(';     $^=')'       ^'['         ;$/=<br />                    '`'|     '.'          ;$,=         '('^<br />                    '}';      $\=         '`'          |((<br />                    '!'        ));       $:=           ')'<br />                    ^((         '}'     ));            $~=<br />                    '*'          |((   '`'              ))<br />                    ;(             ($^))=               ((<br />                    ((              '+'))               ))<br />                    ^+             "\_";$/=             ((<br />                   '&amp;'            ))|+ "\@";            $,<br />                  =((           '['))&amp;  '~';           $\=<br />                 ','^         "\|";$:=   '.'          ^'~'<br />               ;($~)=                                ('@')|<br />             "\(";$^=                               ')'^'['<br /></pre>这就是我们心爱的骆驼。<br /><li>perl camel.pl 它还能运行。而且输出原来的东西。<br /></ol><br />除了骆驼还有很多好玩的形状。试试这个：<br /><pre>use Acme::EyeDrops qw(sightly);<br />    print sightly( { Shape       => 'larry',<br />                     SourceFile  => 'helloworld.pl',<br />                     Regex       => 1 } );</pre>运行 perl t.pl >larry.pl<br />打开 larry.pl 看看会变成什么：<br /><pre>                         ''=~('('.'?'.'{'<br />                      .('`'|'%').('['^"\-").(<br />                 '`'|'!').('`'|',').'"'.(('[')^<br />               '+').                         ('['<br />             ^')'                              ).(<br />           '`'|                                  ')'<br />         ).+(                                   (  '`'<br />        )|((                                    (   '.'<br />       ))))                                  .(  (    '['<br />     )^((                                   (     (    '/'<br />   )))                                    ))       .(   '{'<br />  ^((                                   ((           (   '['<br /> )))                                ))).              (   (((<br />(((                             '\\'                   )   )))<br />)))                         .'"'                        .   (((<br />'`'                ))|'(').(                            (   '`'<br />)|+              ((                                     (    ((<br />'%'             ))                                       )   ))<br />).(            (                                         (   ((<br />'`'            )                                          )))|+<br />','           )                                              .(<br />'`'           |          ',').('`'|'/').('{'^'[').('['^(',')).(<br />'`'           |'/').("\["^    "\)").(    (    (   "\`"))|     (<br />','           )          ) .+(  '`'  |+  (    ( ((  '$'  )))  )<br />).+           (          ( '\\')).'\\'.  (    ( '`')|('.')).  (<br />(((           (          (               (    (               (<br />((   (((     (           (               (    ((              (<br />((   (  '\\')            )               )     ))             )<br />))   )                   )               )     ) )            )<br />))   )  )))               ))).'"'.';'.'"'       . '}'.')');$:=<br />((    (                              (          (          (<br /> (     (                            (          (           (<br />  (     (                            ( '.'    )            )<br />   )      )))                              ))             )<br />    )       )                  )))^'~';$~='@'|'(';$^      =<br />     (      (                ')'))^'[';$/='`'|'.';$,=     (<br />      (     (               '(')))^'}';$\='`'|"\!";$:=   (<br />       (   (                ')'))  )^'}';$~="\*"|  '`';  (<br />        ( (                 $^))  )              =  '+' ^<br />         ((                 '_'   ));$/='&amp;'|'@';#;   #;#<br />          ;                                            #<br />          ;                                           #<br />          ;                                          #<br />         ;       #                                  ;<br />         #        ;                                #<br />         ;          #                             ;<br />         #            ;                          #<br />        ;               #                       ;   #<br />        ;                 #                    ;     #<br />       ;                    #;#              ;#       ;<br />      #                          ;#;#;#;#;#;            #<br /></pre>还有很多很多形状。看看 <a href="http://search.cpan.org/perldoc?Acme::EyeDrops">Acme::EyeDrops</a> 的文档。这是我见过的最棒的模块。<h4>Filter::Simple</h4>这样的 Perl code 看起来像不像密码？<br />perl 中还有个模块 <a href="http://search.cpan.org/perldoc?Filter::Simple">Filter::Simple</a> 专门用来将 perl code 变为谁也看不懂的密码。<br />有空诸位可以试试。<h4>Enjoy!</h4>Have fun. :->><h4>Reference</h4><a href="http://www.perladvent.org/2001/6th/">http://www.perladvent.org/2001/6th/</a></div>
<p><&lt;Previous: <a href="051212.html">my first paid Perl work</a>&nbsp;&nbsp;>>Next: <a href="DateTime.html">[DRAFT]如何处理 Perl 中的时间</a></p>
<p><strong>Options:</strong> <a href='http://del.icio.us/post?title=joy%20in%20Perl&url=http://www.fayland.org/journal/051213.html'>+Del.icio.us</a></p>
<strong>Related items</strong>
<ul><li><a href='Template_Configuration.html'>Template Toolkit 的配置选项</a> < <span class='digit'>2005-10-24 20:23:23</span> ></li><li><a href='template_introduction.html'>Template Toolkit 入门</a> < <span class='digit'>2005-12-03 18:15:26</span> ></li><li><a href='Template_builtin_Filters.html'>Template builtin Filters</a> < <span class='digit'>2005-12-09 23:14:04</span> ></li><li><a href='Template_customized_Filte.html'>Template customized Filters</a> < <span class='digit'>2005-12-10 01:10:15</span> ></li><li><a href='Accessing_External_TTFile.html'>导入 Template Toolkit 文件</a> < <span class='digit'>2005-12-10 22:42:16</span> ></li><li><a href='EmailWithAttachment.html'>发送邮件附件</a> < <span class='digit'>2005-03-23 22:18:40</span> ></li><li><a href='Perl6_Rules.html'>用 Perl6::Rules 来写 Formatter</a> < <span class='digit'>2005-09-27 10:02:45</span> ></li><li><a href='modperl_http_cycle.html'>modperl 服务器的运行阶段和句柄</a> < <span class='digit'>2005-11-22 15:33:08</span> ></li><li><a href='attributes.html'>attributes 用法介绍</a> < <span class='digit'>2005-12-01 00:03:06</span> ></li></ul>
Created on <span class="digit">2005-12-13 00:25:38</span>, Last modified on <span class="digit">2005-12-13 00:40:27</span><br />
Copyright 2004-2005 All Rights Reserved. Powered by <a href="Eplanet.html">Eplanet</a> && <a href='http://catalyst.perl.org'>Catalyst</a> 5.62.
</body>
</html>